<!--
 * @Author: 谢陈洁
 * @Date: 2025-06-30 08:25:44
 * @LastEditors: 谢陈洁
 * @LastEditTime: 2025-07-14 14:34:15
 * @Description:  描述 ：字典单选
-->
<template>
  <el-radio-group v-model="value">
    <el-radio v-for="item in options" :key="item.value" :value="item.value" :name="item.label">
      {{ item.label }}
    </el-radio>
  </el-radio-group>
</template>
<script setup lang="ts">
  import { useDictStore } from '@/stores/dictStore'

  const emit = defineEmits(['update:modelValue'])
  const options = ref<{ label: string; value: string | number }[]>([])
  const dictStore = useDictStore()
  const props = defineProps({
    code: {
      type: String,
      required: true
    },
    modelValue: {
      type: [String, Number],
      default: ''
    }
  })
  const value = ref(props.modelValue + '')

  onMounted(async () => {
    options.value = await dictStore.getDict(props.code)
  })

  watch(
    () => props.modelValue,
    (val: string | number) => {
      value.value = val + ''
    }
  )

  watch(value, (newVal: any) => {
    emit('update:modelValue', newVal)
  })
</script>
